<template>
	<view>
		我的余额:{{money}}

		<button @click="getRecharge">充值</button>
		<input type="number" placeholder="充钱吧!" v-model="rechargeMoney">
	</view>

</template>

<script>
	import {
		getUserinfo,
		getRechargeUserinfo
	} from '../../api/index.js'
	export default {
		data() {
			return {
				money: '',
				rechargeMoney: ''
			};
		},
		mounted() {

		},
		onShow() {

		},
		onLoad() {
			this.getUserinfoMoney()
		},
		methods: {
			// 点击充值 post
			getRecharge() {
				getRechargeUserinfo({
					rechargeMoney: this.rechargeMoney
				}).then(res => {
					console.log(res);
					this.rechargeMoney = ""
					if (res.code == 1) {
						this.$uni.gettitle(res.message)
						setTimeout(() => {
							this.getUserinfoMoney()
						}, 1000)
					} else {
						this.$uni.gettitle(res.message)
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			},
			// 获取用户余额 get
			getUserinfoMoney() {
				getUserinfo().then(res => {
					if (res.code == 1) {
						this.money = res.data.money
					} else {
						this.$uni.gettitle(res.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>